<template>
  <div class="showDoc">
    <!-- 此div用来加载PageOffice客户端控件 -->
    <div style="width:auto; height:1200px;" v-html="poHtmlCode"></div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: 'showDoc',
  data() {
    return {
      poHtmlCode: '',
      issave: '1'
    }
  },
  created() {
    request({
      url: `/api/extend/Document/editFile/` + this.$route.params.vid,
      method: "GET"
    }).then(res => {
      this.poHtmlCode = res.msg;
    }).catch(function (err) {
      console.log(err)
    })
  },
  methods: {
    Close() {
      window.external.close();
    },
    //控件中的一些常用方法都在这里调用，比如保存，打印等等
    OnPageOfficeCtrlInit() {
      // pageofficectrl.AddCustomToolButton("测试按钮", "myTest", 0);
      // PageOffice的初始化事件回调函数，您可以在这里添加自定义按钮
      // PageOffice的初始化事件回调函数，您可以在这里添加自定义按钮
      // 您可以在这里添加自定义按钮，执行您自定义的js。比如添加保存、打印、另存、关闭等按钮
      pageofficectrl.AddCustomToolButton("保存", "Save()", 1);
      // pageofficectrl.AddCustomToolButton("另存为", "SaveAs()", 11);
      pageofficectrl.AddCustomToolButton("定稿", "PrintFile()", 2);
      // pageofficectrl.AddCustomToolButton("全屏", "IsFullScreen()", 3);
      pageofficectrl.AddCustomToolButton("关闭", "Close()", 4);
    },
    Save() {//保存方法
      this.issave = '1';
      pageofficectrl.WebSave();

    },

    PrintFile() {//定稿
      this.issave = '0';
      pageofficectrl.WebSave();




    },
    AfterDocumentOpened() {
      // PageOffice的文档打开后事件回调函数
    },
    BeforeDocumentSaved() {
      // PageOffice的文档保存前事件回调函数
    },
    AfterDocumentSaved() {
      // PageOffice的文档保存后事件回调函数
      // alert('文档保存后事件已执行。');
      if (this.issave == '0') {
        request({
          url: `/api/extend/Document/dingGao/` + this.$route.params.vid,
          method: "GET"
        }).then(res => {
          window.external.close();
        })
      } else {
        window.external.close();
      }
    },
    IsFullScreen() {
      pageofficectrl.IsFullScreen();
    }
  },
  mounted: function () {
    // 将methods中的方法通过mounted挂载到window对象上
    window.mytest = this.mytest;
    window.Save = this.Save;
    // window.SaveAs = this.SaveAs;
    window.PrintFile = this.PrintFile;
    window.IsFullScreen = this.IsFullScreen;
    window.Close = this.Close;

    // 以下的为PageOffice事件的回调函数，名称不能改，否则PageOffice控件调用不到
    window.OnPageOfficeCtrlInit = this.OnPageOfficeCtrlInit;
    window.AfterDocumentOpened = this.AfterDocumentOpened;
    window.BeforeDocumentSaved = this.BeforeDocumentSaved;
    window.AfterDocumentSaved = this.AfterDocumentSaved;
  }
}
</script>
  
